package top.minuy.algorithm.sort.insertion;

import top.minuy.util.constant.SortType;
import top.minuy.util.generate.ArrayGenerator;
import top.minuy.util.helper.SortingHelper;
/**
 * @author Minuy
 * @time 11:48
 * @date 2021/8/21
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("排序测试1：");
        Integer[] d = {8, 1, 3, 1, 2, 4, 9,0};
        InsertionSort.normalSort(d);
        for (Integer i : d) {
            System.out.print(i + " ");
        }
        System.out.println();

        System.out.println("排序测试2：");
        InsertionSort.sort2(d);
        for (Integer i : d) {
            System.out.print(i + " ");
        }
        System.out.println();

        System.out.println("排序测试3：");
        InsertionSort.invertedSort(d);
        for (Integer i : d) {
            System.out.print(i + " ");
        }
        System.out.println();

        System.out.println("性能测试：");

        int[] dataSize = {10, 100, 1000, 10000, 100000};

        for (int n : dataSize) {
            Integer[] arr1 = ArrayGenerator.generateRandomArray(n, n);

            Integer[] arr2 = new Integer[arr1.length];
            System.arraycopy(arr1, 0, arr2, 0, arr1.length);

            SortingHelper.SortTest(SortType.InsertionSort, arr1);
            SortingHelper.SortTest(SortType.InsertionSort2, arr2);
        }


        System.out.println("有序排序对比选择排序性能测试：");

        for (int n : dataSize) {
            Integer[] arr1 = ArrayGenerator.generateOrderedArray(n);

            Integer[] arr2 = new Integer[arr1.length];
            System.arraycopy(arr1, 0, arr2, 0, arr1.length);

            SortingHelper.SortTest(SortType.SelectSort2, arr1);
            SortingHelper.SortTest(SortType.InsertionSort2, arr2);
        }
    }
}
